package com.dcdata.haixin.common;

import java.io.*;
import java.time.LocalDate;

/**
 * @author: xinmi
 * @date: 2020/12/8
 * @description:
 */
public class FileUtils {

    public static String getGpsFileName(){
        String fileName;

        File dataDir = new File(System.getProperty("user.dir") + "/data");
        if (!dataDir.exists() && !dataDir.isDirectory())
            if (!dataDir.mkdir()) {
                System.out.println("mkdir data failed");
            }

        LocalDate localDate = LocalDate.now();
        fileName = System.getProperty("user.dir") + "/data/GPS" + localDate.toString().replace("-", "_") + ".txt";
        return fileName;
    }

    public static String getDaoLiFileName(){
        String fileName;
        File dataDir = new File(System.getProperty("user.dir") + "/data");
        if (!dataDir.exists() && !dataDir.isDirectory())
            if (!dataDir.mkdir()) {
                System.out.println("mkdir data failed");
            }

        LocalDate localDate = LocalDate.now();
        fileName = System.getProperty("user.dir") + "/data/DaoLi" + localDate.toString().replace("-", "_") + ".txt";
        return fileName;
    }

    public static void WriteWithFileName(String fileName, String words) throws IOException {
        try
        {
            FileOutputStream fos = new FileOutputStream(fileName, true);
            fos.write((words + "\n").getBytes());
            fos.close();
        }
        catch(IOException ioe)
        {
            System.out.println("IOException : " + ioe);
        }
    }
}
